package io.renren.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.stereotype.Controller;

import io.renren.entity.DictContractTypeEntity;
import io.renren.service.DictContractTypeService;
import io.renren.utils.PageUtils;
import io.renren.utils.R;
import io.renren.utils.ShiroUtils;


/**
 * 合同类型
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-05-22 16:08:53
 */
@Controller
@RequestMapping("dictcontracttype")
public class DictContractTypeController {
	@Autowired
	private DictContractTypeService dictContractTypeService;
	
	@RequestMapping("/dictcontracttype.html")
	public String list(){
		return "dictcontracttype/dictcontracttype.html";
	}
	
	/**
	 * 列表
	 */
	@ResponseBody
	@RequestMapping("/list")
	@RequiresPermissions("dictcontracttype:list")
	public R list(Integer page, Integer limit){
		Map<String, Object> map = new HashMap<>();
		map.put("offset", (page - 1) * limit);
		map.put("limit", limit);
		
		//查询列表数据
		List<DictContractTypeEntity> dictContractTypeList = dictContractTypeService.queryList(map);
		int total = dictContractTypeService.queryTotal(map);
		
		PageUtils pageUtil = new PageUtils(dictContractTypeList, total, limit, page);
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@ResponseBody
	@RequestMapping("/info/{id}")
	@RequiresPermissions("dictcontracttype:info")
	public R info(@PathVariable("id") String id){
		DictContractTypeEntity dictContractType = dictContractTypeService.queryObject(id);
		
		return R.ok().put("dictContractType", dictContractType);
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@RequestMapping("/save")
	@RequiresPermissions("dictcontracttype:save")
	public R save(@RequestBody DictContractTypeEntity dictContractType){
		dictContractType.setCreateby(ShiroUtils.getUserId().toString());
		dictContractType.setCreatetime(new Date());
		dictContractTypeService.save(dictContractType);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("dictcontracttype:update")
	public R update(@RequestBody DictContractTypeEntity dictContractType){
		dictContractType.setUpdateby(ShiroUtils.getUserId().toString());
		dictContractType.setUpdatetime(new Date());
		dictContractTypeService.update(dictContractType);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@ResponseBody
	@RequestMapping("/delete")
	@RequiresPermissions("dictcontracttype:delete")
	public R delete(@RequestBody String[] ids){
		dictContractTypeService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
